package com.feishi.core.analytic.packing.encode;

import com.feishi.core.util.common.EncryptUtil;
import com.feishi.core.util.common.RSAUtils;

import java.io.ByteArrayOutputStream;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.HashMap;

/**
 * Created by caixq on 6/26 026.
 */
public class EncodeAes128Executor implements EncodeExecutor<EncodeAes128Param> {
    @Override
    public byte[] encode(byte[] bytes, EncodeAes128Param param) {
        return EncryptUtil.getByteFromFormattedText(EncryptUtil.encodeAES128(bytes,param.getPassword()));
    }

    @Override
    public byte[] decode(byte[] bytes, EncodeAes128Param param) {
        return EncryptUtil.decodeAES128(EncryptUtil.getFormattedText(bytes),param.getPassword());
    }
    public static void main(String[] args) {
        EncodeAes128Param param=new EncodeAes128Param("sfdsfsddsf234567");



        ByteArrayOutputStream out=new ByteArrayOutputStream();

        for (int i = 0; i < 1001; i++) {
            out.write((int) (Math.random()*1000));
        }
        String data=EncryptUtil.getFormattedText(out.toByteArray());


        System.out.println(data);

        EncodeAes128Executor executor=new EncodeAes128Executor();
        System.out.println(new String(executor.decode(executor.encode(data.getBytes(),param),param)));
    }
}
